import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Home = ()=>import('../views/home/Home')
const Login = ()=>import('../components/Login.vue')
const relativeGraph =()=>import('../views/relativeGraph/relativeGraph')
const user = ()=>import('../views/user/user')
const goods =()=>import('../views/Good/Good')




const routes=[
  {
    path: '/',
   // redirect: '/login'
     redirect: '/home/Good'
    // 跳过登录界面
  },
  {
    path: '/home',
    component: Home,
    children:[
      // {
      //   path: '/home',
      //   redirect: '/home/relativeGraph'
      // },
      // 重定向的作用是什么
      {
        path:'/home/relativeGraph',
        component:relativeGraph
      },
      {
        path:'/home/user',
        component:user
      },
      {
        path:'/home/Good',
        component:goods
      }
    ]
  },
  {
    path: '/login',
    name:'Login',
    component: Login
  },
]


const router = new VueRouter({
  mode: 'history',
  routes
})

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     next();
//   } else {
//     let token = sessionStorage.getItem('Authorization');
//     console.log(token);
//     if (token !== '1') {
//       //next('/');
//     } else {
//       next();
//     }
//   }
// });
export default router
